﻿
@{
    ViewBag.Title = "Component Selection Management";
    var Groups = ViewBag.Groups as IEnumerable<_PLATFORM.DATA.GROUP>;
    var Selections = ViewBag.SelectionOptions as IEnumerable<_PLATFORM.DATA.SELECTION_OPTION>;
}
<style type="text/css">
#ProductsToSelect
{
    height:100%;
    width:100%;
}
</style>

    <link href="@Url.Content("~/Scripts/jquery-treeview/jquery.treeview.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery-treeview/jquery.treeview.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.cookie.js")" type="text/javascript"></script>
    
    <script type="text/javascript">
        $(document).ready(function () {

            $(".example6").colorbox({ width: "50%", inline: true, href: "#Component" });
            $(".example8").colorbox({ width: "50%", inline: true, href: "#Principle" });
            $(".example9").colorbox({ width: "50%", inline: true, href: "#Type" });
            $(".example10").colorbox({ width: "50%", inline: true, href: "#SpecificType" });

            $("#currentSparePartsSelections").treeview({
                animated: "fast",
                collapsed: true,
                unique: true,
                persist: "cookie",
                toggle: function () {
                    window.console && console.log("%o was toggled", this);
                }
            });


        });

        $(function () {
            $(".colorbox").colorbox({
                overlayClose: false,
                close: "x",
                transition: "none"
            });
        });

        function SelectorUpdateComponents() {
            $.getJSON("/Component/GetComponents", function (data) {
                var items = "";
                $.each(data, function (i, item) {
                    items += "<option value='" + item.Value + "'>" + item.Text + "</option>";
                });

                $("#_S_Components").html(items);
                UpdateSelectionOptions();
            });
        }

        function SelectorUpdatePrinciples() {
            $.getJSON("/Component/GetPrinciples", function (data) {
                var items = "";
                $.each(data, function (i, item) {
                    items += "<option value='" + item.Value + "'>" + item.Text + "</option>";
                });

                $("#_S_Principles").html(items);
                UpdateSelectionOptions();
            });
        }

        function SelectorUpdatePartTypes() {
            $.getJSON("/Component/GetPartTypes", function (data) {
                var items = "";
                $.each(data, function (i, item) {
                    items += "<option value='" + item.Value + "'>" + item.Text + "</option>";
                });

                $("#_S_Types").html(items);
                UpdateSelectionOptions();
            });
        }

        function SelectorUpdateSpecificTypes() {
            $.getJSON("/Component/GetSpecificTypes", function (data) {
                var items = "";
                $.each(data, function (i, item) {
                    items += "<option value='" + item.Value + "'>" + item.Text + "</option>";
                });

                $("#_S_SpecificTypes").html(items);
                UpdateSelectionOptions();
            });
        }

        function UpdateSelectionOptions() {
            $.ajax({
                type: "GET",
                url: "RenderMatrix",
                data: null,
                success: function (result) {
                    $("#currentSparePartsSelections").html(result);

                    $("#currentSparePartsSelections").treeview({
                        animated: "fast",
                        collapsed: true,
                        unique: true,
                        persist: "cookie",
                        toggle: function () {
                            window.console && console.log("%o was toggled", this);
                        }
                    });
                },
                error: function (req, status, error) {
                    alert('Something went wrong!' + error);
                }
            });

        }

        function RenderSelections() {
            $.ajax({
                type: "GET",
                url: "RenderMatrix",
                data: null,
                success: function (result) {
                    $('#currentSparePartsSelections').html(result);

                    $("#currentSparePartsSelections").treeview({
                        animated: "fast",
                        collapsed: true,
                        unique: true,
                        persist: "cookie",
                        toggle: function () {
                            window.console && console.log("%o was toggled", this);
                        }
                    });

                    $.unblockUI;
                    $.unblockUI();
                },
                error: function (req, status, error) { }
            });
        }
    </script>

    <div id="subNav">
        <ul>
    	    <li>@Html.ActionLink("Systems Management", "IndexList", "TruckingSystem")</li>
            @if(ViewBag.ProductType == "Component"){
                <li class="select">@Html.ActionLink("Component Management", "Index", "Component", new { productType = "Component" }, null)</li>
                <li>@Html.ActionLink("Spare Part Management", "Index", "Component", new { productType = "SparePart" }, null)</li>            
            }
            else{
                <li>@Html.ActionLink("Component Management", "Index", "Component", new { productType = "Component" }, null)</li>
                <li class="select">@Html.ActionLink("Spare Part Management", "Index", "Component", new { productType = "SparePart" }, null)</li>
            }
        </ul>
    </div>

    @if (ViewBag.ProductType == "Component")
    {
        <br /><h2>Component Management</h2>
    }
    else { 
        <br /><h2>Spare Part Management</h2>
    }

    <div id="subNav2">
        @if (ViewBag.ProductType == "Component")
        {
            <ul>
    	        <li>@Html.ActionLink("Current Components", "Index", "Component", new { productType = "Component" }, null)</li>
                <li>@Html.ActionLink("Create New Component", "Create", "Component", new { productType = "Component" }, null)<img src="../../Assets/images/add_icon.gif" alt="Add" /></li>
                <li  class="select">@Html.ActionLink("Manage Component Selections", "Index", "SelectionOption", new { productType = "Component" }, null)</li>
            </ul>
        }
        else
        {
            <ul>
    	        <li>@Html.ActionLink("Current Spare Parts", "Index", "Component", new { productType = "SparePart" }, null)</li>
                <li>@Html.ActionLink("Create New Spare Parts", "Create", "Component", new { productType = "SparePart" }, null)<img src="../../Assets/images/add_icon.gif" alt="Add" /></li>
                <li  class="select">@Html.ActionLink("Manage Spare Parts Selections", "Index", "SelectionOption", new { productType = "SparePart" }, null)</li>
            </ul>
        }
    </div>

    <div id="lowerContainer">
        <div id="lowerContainerInner">
            <div style="overflow:visible;">

                @using (Html.BeginForm("CreatePath", "SelectionOption", FormMethod.Post))
                { 
                    <table class="sparePartMgmt" cellpadding="5">
                        <tr>
                            <td style="text-align:left; vertical-align:top;">
                                <div class="title">
                                    @if (ViewBag.ProductType == "Component")
                                    {
                                        <label>Component Groupings</label>
                                    }else{
                                        <label>Spare Part Groupings</label>
                                    }
                	                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@Html.ActionLink("Add New", "Create", new { productType = @ViewBag.ProductType })&nbsp;&nbsp;<img src="../../Assets/images/add_icon.gif" alt="Add" />
                                </div>
                                <div class="padding">
                                    @foreach (var group in Groups)
                                    {
                                        <div class="editor-label">
                                            @Html.Label(group.NAME)
                                        </div>
                                       {
                                           // Find the Selection Options for this group and create a Select List for each
                                           var groupSelections = Selections.Where(s => s.GROUP_ID == group.GROUP_ID);
                                           var selectList = new SelectList(groupSelections, "SELECTION_OPTION_ID", "NAME");
                                           var id = group.NAME;
                                           ViewBag.ID = id;
                            
                                            <div class="editor-field">
                                                @Html.DropDownList(id, selectList)
                                            </div>
                                       }
                                    }
                                    
                                </div>
                                <br />
                                @Html.Label("Check here to Delete the current Selections:") @Html.CheckBox("deleteSelections")
                                @*<input type="checkbox" value="Check to delete selected path" />*@
                            </td>
                            <td style="text-align:left; vertical-align:top;">
                                <div class="title">
                                    Current @ViewBag.ProductType's 
                                </div>
                                <div class="padding">
                                    <div id="top">
                                        <div class="editor-field">
                                            @Html.ListBox("ProductsToSelect", new MultiSelectList(ViewBag.ProductSelectList, "PRODUCT_ID", "NAME"))
                                        </div>
                                    </div>
                                </div>
                            </td>
                            <td style="text-align:left; vertical-align:top;">
                                <div class="title">
                                    Current @ViewBag.ProductType Options
                                </div>
                                <div class="padding">
                                    <div id="bottom">
                                        <ul class="filetree" id="currentSparePartsSelections">
                                            @Html.Action("RenderMatrix3", "SelectionOption")
                                        </ul>
                                    </div>
                                </div>
                
                            </td>
                        </tr>
                    </table>
                    
                    <input type="submit" value="Save" class="button default btnLarge" />
                }
            </div>
        </div>
    </div>
    <hr />
    <p>
        @Html.ActionLink("Edit", "IndexList")
    </p>